package data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;

import fileIO.XLSParser;
import fileIO.CellIO;


/**
 * Retrieves employee data from stored XML files on launch
 * @author lax116
 */
public class PortList {
	private static HashMap<String, String> PortCodeMap;
	private static HashMap<String, String> PortFullMap;
	
	public static void initialize(){
		PortCodeMap = new HashMap<String, String>();
		PortFullMap = new HashMap<String, String>();
		//FilePath.CS_LIST
		HSSFWorkbook PortBook = XLSParser.openXLS(FilePath.PORT_LIST);
		HSSFSheet eSheet = PortBook.getSheetAt(0);
		Iterator<Row> rowIterator = eSheet.iterator();
		while (rowIterator.hasNext()){
			Row eRow = rowIterator.next();
			parseList(eRow);
		}
	}
	private static void parseList(Row row){		
		String PortName = CellIO.ConverttoStr(row.getCell(0));
		String PortCode = CellIO.ConverttoStr(row.getCell(1));
		PortCodeMap.put(PortName, PortCode);
		PortFullMap.put(PortCode, PortName);
	}	
	public static boolean containKey(String key){
		boolean found = false;
		if(PortCodeMap.containsKey(key))
			found = true;
		else if(PortFullMap.containsKey(key))
			found = true;
		return found;
	}
	public static String getCode(String key){
		return PortCodeMap.get(key);
	}
	public static String getName(String key){
		return PortFullMap.get(key);
	}
	public static void AddtoException(String keyS, ArrayList<Row>ArrList){
		//exceptionMap.put(keyS, ArrList);
	}
/*	public static void writeToFile(){
		EmailNoticeWriter.write(exceptionMap, 10);
		//EmployeeInfoWriter.write(shipmentMap,shipmentMap, EmployeeInfoWriter.CS);
	}
	*/
}
